<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Receiver concepts</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../boost_asio.html" title="Boost.Asio">
<link rel="up" href="../reference.html" title="Reference">
<link rel="prev" href="ReadToken.html" title="Read token requirements">
<link rel="next" href="ResolveHandler.html" title="Resolve handler requirements">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="ReadToken.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="ResolveHandler.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_asio.reference.Receiver"></a><a class="link" href="Receiver.html" title="Receiver concepts">Receiver concepts</a>
</h3></div></div></div>
<p>
        A receiver represents the continuation of an asynchronous operation. An asynchronous
        operation may complete with a (possibly empty) set of values, an error, or
        it may be cancelled. A receiver has three principal operations corresponding
        to the three ways an asynchronous operation may complete: <code class="computeroutput"><span class="identifier">set_value</span></code>,
        <code class="computeroutput"><span class="identifier">set_error</span></code>, and <code class="computeroutput"><span class="identifier">set_done</span></code>. These are collectively known
        as a receiver’s <span class="emphasis"><em>completion-signal operations</em></span>.
      </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">E</span> <span class="special">=</span> <span class="identifier">exception_ptr</span><span class="special">&gt;</span>
<span class="identifier">concept</span> <span class="identifier">receiver</span> <span class="special">=</span>
  <span class="identifier">move_constructible</span><span class="special">&lt;</span><span class="identifier">remove_cvref_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&gt;</span> <span class="special">&amp;&amp;</span>
  <span class="identifier">constructible_from</span><span class="special">&lt;</span><span class="identifier">remove_cvref_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;,</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span>
  <span class="identifier">requires</span><span class="special">(</span><span class="identifier">remove_cvref_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;&amp;</span> <span class="identifier">t</span><span class="special">,</span> <span class="identifier">E</span><span class="special">&amp;&amp;</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">{</span>
    <span class="special">{</span> <span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_done</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">t</span><span class="special">))</span> <span class="special">}</span> <span class="keyword">noexcept</span><span class="special">;</span>
    <span class="special">{</span> <span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_error</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">t</span><span class="special">),</span> <span class="special">(</span><span class="identifier">E</span><span class="special">&amp;&amp;)</span> <span class="identifier">e</span><span class="special">)</span> <span class="special">}</span> <span class="keyword">noexcept</span><span class="special">;</span>
  <span class="special">};</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span><span class="special">...</span> <span class="identifier">An</span><span class="special">&gt;</span>
<span class="identifier">concept</span> <span class="identifier">receiver_of</span> <span class="special">=</span>
  <span class="identifier">receiver</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">&amp;&amp;</span>
  <span class="identifier">requires</span><span class="special">(</span><span class="identifier">remove_cvref_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;&amp;</span> <span class="identifier">t</span><span class="special">,</span> <span class="identifier">An</span><span class="special">&amp;&amp;...</span> <span class="identifier">an</span><span class="special">)</span> <span class="special">{</span>
    <span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_value</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">t</span><span class="special">),</span> <span class="special">(</span><span class="identifier">An</span><span class="special">&amp;&amp;)</span> <span class="identifier">an</span><span class="special">...);</span>
  <span class="special">};</span>
</pre>
<p>
        The receiver’s completion-signal operations have semantic requirements
        that are collectively known as the <span class="emphasis"><em>receiver contract</em></span>,
        described below:
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
            None of a receiver’s completion-signal operations shall be invoked
            before <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">start</span></code> has been called on the operation
            state object that was returned by <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">connect</span></code>
            to connect that receiver to a sender.
          </li>
<li class="listitem">
            Once <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">start</span></code> has been called on the operation
            state object, exactly one of the receiver’s completion-signal operations
            shall complete non-exceptionally before the receiver is destroyed.
          </li>
<li class="listitem">
            If <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_value</span></code> exits with an exception,
            it is still valid to call <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_error</span></code>
            or <code class="computeroutput"><span class="identifier">execution</span><span class="special">::</span><span class="identifier">set_done</span></code> on the receiver.
          </li>
</ul></div>
<p>
        Once one of a receiver’s completion-signal operations has completed non-exceptionally,
        the receiver contract has been satisfied.
      </p>
</div>
<div class="copyright-footer">Copyright © 2003-2023 Christopher M. Kohlhoff<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="ReadToken.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="ResolveHandler.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
